package com.glsc.ngateway.common.api.flowable.dto.demand;

import cn.hutool.core.util.StrUtil;
import com.glsc.ngateway.common.api.common.utils.DateUtil;
import com.glsc.ngateway.common.api.flowable.dto.param.ParamSearchDto;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ParamSearchDtoBuilder {

    @ApiModelProperty(value = "流程id")
    private String processId;
    @ApiModelProperty(value = "节点id")
    private String taskId;
    private String startUser;
    private String dealUser;
    private String involveUser;
    private String title;
    private String processDefineKey;
    private String sysid;
    private String beginDate;
    private String endDate;
    @ApiModelProperty(value = "是否结束，0未结束，1已结束")
    private String hasProcessEnd;

    @ApiModelProperty(value = "是否结束，0未结束，1已结束")
    private Boolean archived;

    public ParamSearchDtoBuilder(RqListType rqListType, String createProject, String userId) {
        this.processDefineKey = "DemandManagement";
        this.sysid = createProject;
        if (RqListType.TODO.equals(rqListType)) {//待办
            this.dealUser = userId;
        } else if (RqListType.RELATED.equals(rqListType)) {//已办
            this.involveUser = userId;
        } else if (RqListType.MINE.equals(rqListType)) {//我发起的
            this.startUser = userId;
        } else {
            this.involveUser = userId;//默认为：已办（我参与过的流程）
        }
    }

    public ParamSearchDtoBuilder setArchived(Boolean archived) {
        this.archived = archived;
        return this;
    }

    public ParamSearchDtoBuilder setTitle(String title) {
        this.title = title;
        return this;
    }

    public ParamSearchDtoBuilder setHasProcessEnd(String hasProcessEnd) {
        this.hasProcessEnd = hasProcessEnd;
        return this;
    }

    public ParamSearchDtoBuilder setDealUser(String dealUser) {
        if (StrUtil.isNotEmpty(dealUser)){
            this.dealUser = dealUser;
        }
        return this;
    }

    public ParamSearchDtoBuilder setBeginDate(LocalDate beginDate) {
        this.beginDate = DateUtil.getStr_yyyyMMdd(beginDate);
        return this;
    }

    public ParamSearchDtoBuilder setEndDate(LocalDate endDate) {
        this.endDate = DateUtil.getStr_yyyyMMdd(endDate);
        return this;
    }

    public ParamSearchDto build() {
        return new ParamSearchDto(this);
    }

    public String getStartUser() {
        return startUser;
    }

    public String getDealUser() {
        return dealUser;
    }

    public String getInvolveUser() {
        return involveUser;
    }

    public String getTitle() {
        return title;
    }

    public String getSysid() {
        return sysid;
    }

    public String getBeginDate() {
        return beginDate;
    }

    public String getEndDate() {
        return endDate;
    }

    public String getProcessDefineKey() {
        return processDefineKey;
    }

    public String getHasProcessEnd() {
        return hasProcessEnd;
    }
}
